<?php
declare (strict_types = 1);

namespace app\model\admin;

use app\model\AdminBaseModel;

/**
 * @mixin \think\Model
 */
class SysUser extends AdminBaseModel
{
    //
    // 数据表名称
    protected $table = 'sys_user';
    protected $scopeField = true;

    //可搜索字段
    protected $searchField = [];
    protected $singleSearchField = ['username','nickname'];
    //可作为条件的字段
    protected $whereField = ['dept_id', 'status'];
    //可做为时间范围查询的字段
    protected $timeField = ['create_time'];
    //不允许删除的ID
    public $noDeletionId = [1, 100];

    public function createToken()
    {
        return $this->getAttr('username');
    }

    public function dept(){
        return $this->belongsTo(SysDept::class, 'dept_id');
    }

    public function roles(){
        return $this->belongsToMany(SysRole::class, SysUserRole::class, 'role_id', 'user_id');

    }

    public function setPasswordAttr($value)
    {
        return md5($value);
    }
    
}
